#include <stdio.h>
#include <stdlib.h>

int swap(int* x, int* y);
int quick_sort(int arr[], int head, int tail);  // 递减排序
int horse_strategy(int arr_qi[], int arr_tian[], int n);

int main(int argc, char const *argv[]) {
	int n;
	int i;
	int* arr_qi;
	int* arr_tian;

	printf("length of arr: ");
	scanf("%d", &n);
	arr_qi = (int*)malloc(sizeof(int) * n);
	arr_tian = (int*)malloc(sizeof(int) * n);

	printf("arr_t[]: ");
	for (i = 0; i < n; ++i) {
		scanf("%d", &arr_tian[i]);
	}
	printf("arr_q[]: ");
	for (i = 0; i < n; ++i) {
		scanf("%d", &arr_qi[i]);
	}

	quick_sort(arr_qi, 0, n-1);
	quick_sort(arr_tian, 0, n-1);

	printf("\nresult: %d\n", horse_strategy(arr_qi, arr_tian, n));

	free(arr_qi);
	free(arr_tian);

	return 0;
}

int swap(int* x, int* y) {
	int temp = *x;
	*x = *y;
	*y = temp;

	return 0;
}

int quick_sort(int arr[], int head, int tail) {
	int key = arr[head];
	int i = head;
	int j = tail;
	if (tail <= 0) return 0;
	while (i < j) {
		while (i < j && key >= arr[j]) --j;
		while (i < j && key <= arr[i]) ++i;
		if (i < j) swap(&arr[i], &arr[j]);
	}
	swap(&key, &arr[i]);

	if (i - 1 > head) quick_sort(arr, head, i-1);
	if (i + 1 < tail) quick_sort(arr, i + 1, tail);

	return 0;
}

int horse_strategy(int arr_qi[], int arr_tian[], int n) {
	int qhead = 0;
	int qtail = n - 1;
	int thead = 0;
	int ttail = n - 1;
	int win_sum = 0;

	if (n <= 0) return 0;

	while (qhead <= qtail) {
		// 最强v最强 强则拿下一局
		if (arr_tian[thead] > arr_qi[qhead]) {
			win_sum += 1;
			++qhead;
			++thead;
		}
		// 最强v最强 弱则拿最弱消耗
		else if (arr_tian[thead] < arr_qi[qhead]) {
			win_sum -= 1;
			--ttail;
			++qhead;
		}
		// 最强v最强 相等比较最弱
		else {
			// 最弱v最弱 强则拿下一局
			if (arr_tian[ttail] > arr_qi[qtail]) {
				win_sum += 1;
				--ttail;
				--qtail;
			}
			// 最弱v最弱 弱则消耗最强
			else if (arr_tian[ttail] < arr_qi[qtail]) {
				win_sum -= 1;
				--ttail;
				++qhead;
			}
			// 相等 不胜不输但都消耗
			else {
				--ttail;
				--qtail;
			}
		}
	}

	return win_sum * 200;
}